// AnnoWnd.cpp : implementation file
//

#include "stdafx.h"
#include "EJWork.h"
#include "AnnoWnd.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAnnoWnd

CAnnoWnd::CAnnoWnd()
{
	index = 0;
	page = NULL;
	bmi = NULL;
	bmp = NULL;
}

CAnnoWnd::~CAnnoWnd()
{
}


BEGIN_MESSAGE_MAP(CAnnoWnd, CStatic)
	//{{AFX_MSG_MAP(CAnnoWnd)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAnnoWnd message handlers

void CAnnoWnd::OnPaint() 
{
	long cx,cy;
	long dx,dy;
	CRect rc;

	CPaintDC dc(this); // device context for painting

	GetClientRect(&rc);
	dc.SelectStockObject(BLACK_PEN);
	dc.SelectStockObject(NULL_BRUSH);
	
	if (page)
	{
		const CEJAnno& anno = page->anno[index];

		if (anno.box.Width()>anno.box.Height())
		{
			cx = rc.Width();
			cy = (double)anno.box.Height()/(double)anno.box.Width()*(double)cx;
		}
		else
		{
			cy = rc.Height();
			cx = (double)anno.box.Width()/(double)anno.box.Height()*(double)cy;
		}
		dx = (rc.Width()-cx)/2;
		dy = (rc.Height()-cy)/2;

		dc.SetStretchBltMode(HALFTONE);
		::StretchDIBits(dc.m_hDC,
			dx,dy,cx,cy,
//			0, 0, rc.Width(), rc.Height(),
//			anno.box.left, anno.box.Height() - anno.box.top, anno.box.Width(),-anno.box.Height(),
			anno.box.left,page->size.cy-anno.box.bottom,
			anno.box.Width(),anno.box.Height(),
			bmp, bmi, DIB_RGB_COLORS, SRCCOPY );

		dc.Rectangle(dx,dy,dx+cx,dy+cy);

	}


}
